<template>
	<el-main class="bg edit_wrap comtable_e">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce"> 
							<el-col v-if="$check_field('get','project_manager') || $check_field('add','project_manager') || $check_field('set','project_manager')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="项目经理" prop="project_manager">
																<el-select v-if="(form['project_team_id'] && $check_field('set','project_manager')) || (!form['project_team_id'] && $check_field('add','project_manager'))" id="project_manager" v-model="form['project_manager']" :disabled="disabledObj['project_manager_isDisabled']">
							<el-option v-for="o in list_user_project_manager" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select v-else-if="$check_field('get','project_manager')" id="project_manager" v-model="form['project_manager']" :disabled="true">
							<el-option v-for="o in list_user_project_manager" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','project_number') || $check_field('add','project_number') || $check_field('set','project_number')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="项目编号" prop="project_number">
															<el-input id="project_number" v-model="form['project_number']" placeholder="请输入项目编号"
							  v-if="(form['project_team_id'] && $check_field('set','project_number')) || (!form['project_team_id'] && $check_field('add','project_number'))" :disabled="disabledObj['project_number_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','project_number')">{{form['project_number']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','entry_name') || $check_field('add','entry_name') || $check_field('set','entry_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="项目名称" prop="entry_name">
															<el-input id="entry_name" v-model="form['entry_name']" placeholder="请输入项目名称"
							  v-if="(form['project_team_id'] && $check_field('set','entry_name')) || (!form['project_team_id'] && $check_field('add','entry_name'))" :disabled="disabledObj['entry_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','entry_name')">{{form['entry_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','project_budget') || $check_field('add','project_budget') || $check_field('set','project_budget')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="项目预算" prop="project_budget">
															<el-input id="project_budget" v-model="form['project_budget']" placeholder="请输入项目预算"
							  v-if="(form['project_team_id'] && $check_field('set','project_budget')) || (!form['project_team_id'] && $check_field('add','project_budget'))" :disabled="disabledObj['project_budget_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','project_budget')">{{form['project_budget']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','start_date') || $check_field('add','start_date') || $check_field('set','start_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="开始日期" prop="start_date">
															<el-input id="start_date" v-model="form['start_date']" placeholder="请输入开始日期"
							  v-if="(form['project_team_id'] && $check_field('set','start_date')) || (!form['project_team_id'] && $check_field('add','start_date'))" :disabled="disabledObj['start_date_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','start_date')">{{form['start_date']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','closing_date') || $check_field('add','closing_date') || $check_field('set','closing_date')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="截止日期" prop="closing_date">
															<el-input id="closing_date" v-model="form['closing_date']" placeholder="请输入截止日期"
							  v-if="(form['project_team_id'] && $check_field('set','closing_date')) || (!form['project_team_id'] && $check_field('add','closing_date'))" :disabled="disabledObj['closing_date_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','closing_date')">{{form['closing_date']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','team_name') || $check_field('add','team_name') || $check_field('set','team_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="团队名称" prop="team_name">
															<el-input id="team_name" v-model="form['team_name']" placeholder="请输入团队名称"
							  v-if="(form['project_team_id'] && $check_field('set','team_name')) || (!form['project_team_id'] && $check_field('add','team_name'))" :disabled="disabledObj['team_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','team_name')">{{form['team_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','team_size') || $check_field('add','team_size') || $check_field('set','team_size')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="团队人数" prop="team_size">
											<el-input-number id="team_size" v-model.number="form['team_size']"
						v-if="(form['project_team_id'] && $check_field('set','team_size')) || (!form['project_team_id'] && $check_field('add','team_size'))" :disabled="disabledObj['team_size_isDisabled']"></el-input-number>
					<div v-else-if="$check_field('get','team_size')">{{form['team_size']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','development_member') || $check_field('add','development_member') || $check_field('set','development_member')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="开发成员" prop="development_member">
											<el-select id="development_member" v-model="development_member_multiple_value" multiple @change="select_development_member_multiple"
							   v-if="(form['project_team_id'] && $check_field('set','development_member')) || (!form['project_team_id'] && $check_field('add','development_member'))">
												<el-option v-for="o in list_development_member" :key="o['user_name']" :label="o['user_name']"
								   :value="o['user_name']">
						</el-option>
											</el-select>
					<div v-else-if="$check_field('get','development_member')">{{form['development_member']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','test_member') || $check_field('add','test_member') || $check_field('set','test_member')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="测试成员" prop="test_member">
											<el-select id="test_member" v-model="test_member_multiple_value" multiple @change="select_test_member_multiple"
							   v-if="(form['project_team_id'] && $check_field('set','test_member')) || (!form['project_team_id'] && $check_field('add','test_member'))">
												<el-option v-for="o in list_test_member" :key="o['user_name']" :label="o['user_name']"
								   :value="o['user_name']">
						</el-option>
											</el-select>
					<div v-else-if="$check_field('get','test_member')">{{form['test_member']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','team_division_of_labor') || $check_field('add','team_division_of_labor') || $check_field('set','team_division_of_labor')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="团队分工" prop="team_division_of_labor">
											<el-input type="textarea" id="team_division_of_labor" v-model="form['team_division_of_labor']" placeholder="请输入团队分工"
						v-if="(form['project_team_id'] && $check_field('set','team_division_of_labor')) || (!form['project_team_id'] && $check_field('add','team_division_of_labor'))" :disabled="disabledObj['team_division_of_labor_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','team_division_of_labor')">{{form['team_division_of_labor']}}</div>
							</el-form-item>
			</el-col>
						
	
	
		
		
						<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp" v-if="!form['source_user_id'] && 0 > 0">
			  <el-form-item label="分配任务限次">
				<el-input id="limit_times" v-model="form['task_allocation_limit_times']" placeholder="分配任务限制次数，0为不限"
						  v-if="$check_option('/project_team/view','can_limits')"
				></el-input>
				<div v-else-if="$check_action('/project_team/view','get')" v-html="form['task_allocation_limit_times']"></div>
			  </el-form-item>
			</el-col>
					<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp" v-if="!form['source_user_id'] && 0 > 0">
			  <el-form-item label="成本限次">
				<el-input id="limit_times" v-model="form['cost_report_limit_times']" placeholder="成本限制次数，0为不限"
						  v-if="$check_option('/project_team/view','can_limits')"
				></el-input>
				<div v-else-if="$check_action('/project_team/view','get')" v-html="form['cost_report_limit_times']"></div>
			  </el-form-item>
			</el-col>
			
	
	
		
		
	
		</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/project_team/view','set') || $check_action('/project_team/view','add') || $check_option('/project_team/table','examine')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";
	export default {
		mixins: [mixin],
		data() {
			return {
				field: "project_team_id",
				url_add: "~/api/project_team/add?",
				url_set: "~/api/project_team/set?",
				url_get_obj: "~/api/project_team/get_obj?",
				url_upload: "~/api/project_team/upload?",

				query: {
					"project_team_id": 0,
				},

				form: {
								"project_manager": 0, // 项目经理
										"project_number":  '', // 项目编号
										"entry_name":  '', // 项目名称
										"project_budget":  '', // 项目预算
										"start_date":  '', // 开始日期
										"closing_date":  '', // 截止日期
										"team_name":  '', // 团队名称
										"team_size":  0, // 团队人数
										"development_member":  '', // 开发成员
										"test_member":  '', // 测试成员
										"team_division_of_labor":  '', // 团队分工
											"project_team_id": 0, // ID
													"task_allocation_limit_times": 0, // 分配任务限制次数
							"cost_report_limit_times": 0, // 成本限制次数
												},
				disabledObj:{
								"project_manager_isDisabled": false,
										"project_number_isDisabled": false,
										"entry_name_isDisabled": false,
										"project_budget_isDisabled": false,
										"start_date_isDisabled": false,
										"closing_date_isDisabled": false,
										"team_name_isDisabled": false,
					          			"team_size_isDisabled": false,
										"development_member_isDisabled": false,
										"test_member_isDisabled": false,
										"team_division_of_labor_isDisabled": false,
										},

	
					// 用户列表
				list_user_project_manager: [],
					
			
			
			
			
			
			
									development_member_multiple_value:[],
						// 开发成员选项列表
				list_development_member: [""],
	
									test_member_multiple_value:[],
						// 测试成员选项列表
				list_test_member: [""],
	
			
		
			}
		},
		methods: {

	
	
				/**
			 * 获取项目经理用户列表
			 */
			async get_list_user_project_manager() {
                var json = await this.$get("~/api/user/get_list?user_group=项目经理");
                if(json.result && json.result.list){
                    this.list_user_project_manager = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_project_manager(id){
				var obj = this.list_user_project_manager.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			
	
			
	
			
	
			
	
			
	
			
	
			
	
			
				/**
			 * 获取开发成员列表
			 */
			
						async get_list_development_member() {
				var json = await this.$get("~/api/develop_users/get_list?");
				if(json.result && json.result.list){
					this.list_development_member = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},
										select_development_member_multiple(v){
							this.form.development_member = "";
							if (v && v.length > 0) {
								this.form.development_member = v.toString();
							}
						},
			
			
				/**
			 * 获取测试成员列表
			 */
			
						async get_list_test_member() {
				var json = await this.$get("~/api/test_user/get_list?");
				if(json.result && json.result.list){
					this.list_test_member = json.result.list;
				}
				else if(json.error){
					console.error(json.error);
				}
			},
										select_test_member_multiple(v){
							this.form.test_member = "";
							if (v && v.length > 0) {
								this.form.test_member = v.toString();
							}
						},
			
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
											// 获取缓存数据附加
				form = $.db.get("form");
									$.push(this.form ,form);
																																				
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
																										$.db.del("form");

				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
																																																		if (this.form.development_member){
					this.development_member_multiple_value = this.form.development_member.split(",")
				}
														if (this.form.test_member){
					this.test_member_multiple_value = this.form.test_member.split(",")
				}
									

			},

																																																																																									async submit(param, func){
				if (!param) {
					param = this.form;
				}
						
				var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
																																																																																					ret = this.events("submit_main", pm, func);
				}
				return ret;
			},
			
			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {
					
																																																																																																																															return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/project_team/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/project_team/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/project_team/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/project_team/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/project_team/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
					this.get_list_user_project_manager();
																					this.get_list_development_member();
						this.get_list_test_member();
						},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
	
	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}




	
</style>
